﻿/*===Ajax请求实体Start===*/
var AjaxEntity = function () { };
AjaxEntity.prototype =
    {
        //请求地址
        url: "",
        //请求参数
        data: {},
        //请求方式
        type: "POST",
        //默认返回数据为json格式
        dataType: "json",
        //内容类型
        contentType: "application/x-www-form-urlencoded",
        //是否异步请求
        async: true,
        //是否缓存
        cache: false,
        //请求前事件
        executing: function () {
            return true;
        },
        //请求失败事件
        executeFailed: function () {
        },
        //请求事件
        execute: function () {
            if (!this.executing()) {
                this.executeFailed();
                return;
            }
            var $this = this;
            $.ajax({
                cache: this.cache,
                type: this.type,
                url: this.url,
                data: this.data,
                dataType: this.dataType,
                contentType: this.contentType,
                async: this.async,
                success: function (objInvokeResult) {
                    $this.executeSuccess(objInvokeResult);
                    $this.executed();
                }
            });
        },
        //请求成功事件
        executeSuccess: function (invokeresult) {
        },
        //请求完成事件
        executed: function () {
        }
    };
/*===Ajax请求实体End===*/

//Json日期串后转成日期格式
function JsonToDate(objJsonDate, isShowDetail) {
    if (!objJsonDate) {
        return "";
    }
    var objDate = new Date(Number(objJsonDate.replace("/Date(", "").replace(")/", "")));
    if (typeof (isShowDetail) == "undefined") {
        isShowDetail = true;
    }
    return FormatDate(objDate, isShowDetail);
}

//日期格式化
function FormatDate(objDate, isShowDetail) {
    if (!objDate) {
        return "";
    }
    var objYear = objDate.getFullYear();
    var objMonth = objDate.getMonth();
    objMonth = objMonth + 1 < 10 ? "0" + (objMonth + 1) : objMonth + 1;
    var objDay = objDate.getDate();
    objDay = objDay < 10 ? "0" + objDay : objDay;
    if (typeof (isShowDetail) == "undefined") {
        isShowDetail = true;
    }
    if (isShowDetail) {
        var objHour = objDate.getHours();
        objHour = objHour < 10 ? "0" + objHour : objHour;
        var objMinute = objDate.getMinutes();
        objMinute = objMinute < 10 ? "0" + objMinute : objMinute;
        var objSecond = objDate.getSeconds();
        objSecond = objSecond < 10 ? "0" + objSecond : objSecond;
        return objYear + "-" + objMonth + "-" + objDay + " " + objHour + ":" + objMinute + ":" + objSecond;
    }
    return objYear + "-" + objMonth + "-" + objDay;
}

function ParserDate(objDateString) {
    if (!objDateString) return new Date();
    var objDate = (objDateString.split(' '));
    var ymd = (objDate[0].split('-'));
    var objYear = parseInt(ymd[0], 10);
    var objMonth = parseInt(ymd[1], 10);
    var objDay = parseInt(ymd[2], 10);
    var hms = (objDate[1].split(':'));
    var objHour = parseInt(hms[0], 10);
    var objMinute = parseInt(hms[1], 10);
    var objSecond = parseInt(hms[2], 10);
    if (!isNaN(objYear) && !isNaN(objMonth) && !isNaN(objDay) && !isNaN(objHour) && !isNaN(objMinute) && !isNaN(objSecond)) {
        return new Date(objYear, objMonth - 1, objDay, objHour, objMinute, objSecond);
    } else {
        return new Date();
    }
}